<html>
<head><meta charset="utf-8"><title>passing tcx around for interning · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html">passing tcx around for interning</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="177902078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902078">(Oct 11 2019 at 12:29)</a>:</h4>
<p>was talking with <span class="user-mention" data-user-id="124288">@oli</span> about a problem that is starting to show up when you intern projections</p>



<a name="177902090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902090">(Oct 11 2019 at 12:29)</a>:</h4>
<p>you need to pass <code>tcx: TyCtxt&lt;'tcx&gt;</code> around in a lot of places</p>



<a name="177902171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902171">(Oct 11 2019 at 12:30)</a>:</h4>
<p>one is that <code>MutVisitor</code> is going to need a blank <code>tcx() -&gt; TyCtxt&lt;'tcx&gt;</code> and implementors can roll their own thing</p>



<a name="177902176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902176">(Oct 11 2019 at 12:30)</a>:</h4>
<p>that's not thaat bad</p>



<a name="177902202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902202">(Oct 11 2019 at 12:31)</a>:</h4>
<p>besides needing to implement it in a lot of cases that are not even going to use it because they don't need to reintern place because they don't mutate it</p>



<a name="177902268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902268">(Oct 11 2019 at 12:32)</a>:</h4>
<p>but one of the main problems is <a href="https://github.com/rust-lang/rust/blob/master/src/librustc/mir/mod.rs#L1862-L1894" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc/mir/mod.rs#L1862-L1894">https://github.com/rust-lang/rust/blob/master/src/librustc/mir/mod.rs#L1862-L1894</a></p>



<a name="177902276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902276">(Oct 11 2019 at 12:32)</a>:</h4>
<p>passing <code>tcx</code> there may be kind of a pain</p>



<a name="177902287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902287">(Oct 11 2019 at 12:32)</a>:</h4>
<p>unsure if I should follow that path or is there any smarter idea</p>



<a name="177902798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902798">(Oct 11 2019 at 12:39)</a>:</h4>
<p>/cc <span class="user-mention" data-user-id="119009">@eddyb</span> <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="177902936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177902936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177902936">(Oct 11 2019 at 12:41)</a>:</h4>
<p>It's probably not too bad to fiddle through <code>TyCtxt</code>. Alternatively we can have <code>tcx.mk_place</code> that takes a <code>PlaceBase</code> and a <code>Vec&lt;PlaceElem&gt;</code> and just require the caller to work with <code>TyCtxt</code> directly instead of offering convenience functions</p>



<a name="177947234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177947234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177947234">(Oct 11 2019 at 20:41)</a>:</h4>
<p>this is aways the annoying question</p>



<a name="177947236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177947236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177947236">(Oct 11 2019 at 20:41)</a>:</h4>
<p>whether to do <code>tcx.foo(a, b)</code> or <code>a.foo(tcx, b)</code></p>



<a name="177947249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177947249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177947249">(Oct 11 2019 at 20:41)</a>:</h4>
<p>I can never make up my mind which I like better</p>



<a name="177947272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177947272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177947272">(Oct 11 2019 at 20:42)</a>:</h4>
<p>mostly I feel there is a missing language feature (maybe like scala implicits) to enable <code>a.foo(b)</code> while still passing (implicitly) the <code>tcx</code></p>



<a name="177947297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177947297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177947297">(Oct 11 2019 at 20:42)</a>:</h4>
<p>but oh well</p>



<a name="177947340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177947340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177947340">(Oct 11 2019 at 20:42)</a>:</h4>
<p>certainly not unique to Rust</p>



<a name="177948314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177948314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177948314">(Oct 11 2019 at 20:53)</a>:</h4>
<p>was tempted to do some weird thing with <code>ty::tls::with(|tcx| tcx.intern_place_elems(...), ty)</code></p>



<a name="177948362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/passing%20tcx%20around%20for%20interning/near/177948362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/passing.20tcx.20around.20for.20interning.html#177948362">(Oct 11 2019 at 20:53)</a>:</h4>
<p>that gives lifetimes problems but I'm pretty sure that can be hacked with some unsafe sorcery :P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>